import type { YouDaoTranslateBody } from "@/types/youdao";
import { HTTPS_TRANSLATE_URL, APP_ID, SECRET_KEY } from '@/config/youdao';
/**
 * 有道翻译
 */
export function useYouDaoTranslate() {

    /**
     * 文本翻译
     * @param body 参数 类型为`YouDaoTranslateBody`
     * @returns 
     */
    const httpsTextTranslate = async (body: YouDaoTranslateBody) => {
        return await fetch('/youdao' + HTTPS_TRANSLATE_URL, {
            method: 'POST',
            headers: {
                "Content-Type": "application/x-www-form-urlencoded"
            },
            body: JSON.stringify(body)
        })
        .then(response => response.json())
        .catch(err => err.json())
    }

    return {
        httpsTextTranslate: httpsTextTranslate
    }
}